﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cotizav.CONTROLADOR;
using Cotizav.PRESENTACION.Controls;
using Cotizav.CONEXION;

namespace Cotizav.PRESENTACION.CartaCompromiso
{
    public partial class PanelCartaCompromiso : Form
    {
        IUCartaCompromiso iuCartaCompromiso;
        CtrlCartaCompromiso ctCartaCompromiso;
        CtrlCartaCompromisoDetalle ctCartaCompromisoDetalle;

        public PanelCartaCompromiso()
        {
            InitializeComponent();

            iuCartaCompromiso = new IUCartaCompromiso();
            ctCartaCompromiso = new CtrlCartaCompromiso();
            ctCartaCompromisoDetalle = new CtrlCartaCompromisoDetalle();
        }

        private void PanelCartaCompromiso_Load(object sender, EventArgs e)
        {
            loadGridCartaCompromiso();
        }

        internal void loadGridCartaCompromiso()
        {
            SplitContainer panelMaestro = panelRegistro.Controls["splitContainer1"] as SplitContainer;
            panelMaestro.Panel2.Controls.Add(iuCartaCompromiso);

            DataGridView dg = panelMaestro.Panel1.Controls["gridListObjetos"] as DataGridView;
            AutoCompleteTextbox completeTextBox = panelMaestro.Panel1.Controls["txtBuscarContains"] as AutoCompleteTextbox;
            List<CARTA_COMPROMISO> cartaCompromisos = ctCartaCompromiso.getListCartaCompromiso();
            
            dg.DataSource = null;
            dg.DataSource = cartaCompromisos;
            dg.ClearSelection();

            completeTextBox.AutoCompleteList = cartaCompromisos.Select(x => x.nombrecliente).ToList<string>();
            panelRegistro.ColumnFiltered = "nombrecliente";
        }
    }
}
